<?php

class OpenSearch
{  
	// public myspaceContext
   
    public $context = NULL;
  
  /**
   * Sets up the OpenSearch with MySpace Context
   *
   * @param MySpaceContext $context
   * @return object a new opensearch object
   */
    
   public function __construct($context)  {
     $this->context = $context;
   }
   
  /*
   *  Open Search
   *  Resource: http://api.myspace.com/opensearch/people?
   *  Details:  http://wiki.developer.myspace.com/index.php?title=Open_Search
   *  Description: Get People Search
   *  @param mixed   $searchTerms   search keywords
   *  @param integer $startIndex    Indicates the index of the first item to retrieve from the query set
   *  @param integer $count			total number of records
   *  @param string  $searchBy      which field the search should go through. Default is all the fields (yomi is only available to ja-jp culture) [ex. searchBy=name or searchBy=displayname or searchBy=email or searchBy=yomi] 
   *  @param string  $gender        the gender to filter on; default is no preference or both [ex. gender=m or gender=f] 
   *  @param bool    $hasPhoto      filter for those who only has photo; default is either [ex. hasPhoto=on] 
   *  @param integer $minAge        minimum age to start the search (same filter as site search) [ex. minAge=18] 
   *  @param integer $maxAge        maximum age to end the search with (same filter as site search) [ex. maxAge=68] 
   *  @param string  $location      the location field such as city state and country to search for [ex. location=US] 
   *  @param integer $distance      distance away from location to return results; default is miles; depending on culture passed in it can be kilometers [ex. distance=25] 
   *  @param mixed   $latitude 	    geo latitude to search; combination with longitude required when used [ex. latitude=1] (does not work with location field) 
   *  @param mixed   $longitude     geo longtitude to search; combination with latitude is required when used [ex. longitude=1] (does not work with location field) 
   *  @param string  $culture 		the culture context of the search; for instance japan is ja-jp; default is en-us [ex. culture=en-us] 
   *  @param string  $countryCode   countryCode to search with [ex. countryCode=CA] (this is similar to culture=en-CA) 
   *  @return object of php object representing the JSON in which the list of search
   */
  
  public function searchPeople($searchTerms, $startPage=1, $count=10, $searchBy=NULL, $gender=NULL, $hasPhoto=NULL, $minAge=NULL, $maxAge=NULL, $location=NULL, $distance=NULL, $latitude=NULL, $longitude=NULL, $culture=NULL, $countryCode=NULL)
  {

  	$REST = "http://api.myspace.com/opensearch/people?";
  	$params = array('format' => 'json', 
  					'searchTerms' => $searchTerms,
  					'count' => (empty($count) ? 10 : $count),
  					'startPage' => (empty($startPage) ? 1 : $startPage),
  					'searchBy' => $searchBy,
  					'gender' => $gender,
  					'hasPhoto' => $hasPhoto,
  					'minAge' => $minAge,
  					'maxAge' => $maxAge,
  					'location' => $location,
  					'distance' => $distance,
  					'latitude' => $latitude,
  					'longitude' => $longitude,
  					'culture' => $culture,
  					'countryCode' => $countryCode);  					
	
  	$responseJSON = $this->context->call($REST, $params, 'GET');
  	//parseJSON is a static method and does not effect the object
  	return MySpaceUtils::parseJSON($responseJSON);

  }
  
   /*
   *  Open Search
   *  Resource: http://api.myspace.com/opensearch/images?
   *  Details:  http://wiki.developer.myspace.com/index.php?title=Open_Search
   *  Description: Get Image Search
   *  @param mixed   $searchTerms   search keywords
   *  @param integer $startIndex    Indicates the index of the first item to retrieve from the query set
   *  @param integer $count			total number of records
   *  @param string  $searchBy      which field the search should go through. Default is all the fields (yomi is only available to ja-jp culture) [ex. searchBy=name or searchBy=displayname or searchBy=email or searchBy=yomi] 
   *  @param string  $culture 		the culture context of the search; for instance japan is ja-jp; default is en-us [ex. culture=en-us] 
   *  @param string  $sortBy        Ways to sort the images; when excluded sortBy is all [ex. sortBy=popular or sortBy=recent]
   *  @param string  $sortOrder     Order of the image sorting which can be descending (default) or ascending [ex. sortOrder=asc] 
   *  @return object of php object representing the JSON in which the list of search
   */
  
  public function searchImages($searchTerms, $startPage=1, $count=10,  $searchBy=NULL, $culture=NULL, $sortBy=NULL, $sortOrder=NULL)
  {

  	$REST = "http://api.myspace.com/opensearch/images?";
  	$params = array('format' => 'json', 
  					'searchTerms' => $searchTerms,
  					'count' => (empty($count) ? 10 : $count),
  					'startPage' => (empty($startPage) ? 1 : $startPage),
  					'culture' => $culture,
  					'sortBy' => $sortBy,
  					'sortOrder' => $sortOrder);  					
	
  	$responseJSON = $this->context->call($REST, $params, 'GET');
  	//parseJSON is a static method and does not effect the object
  	return MySpaceUtils::parseJSON($responseJSON);

  }
  
   /*
   *  Open Search
   *  Resource: http://api.myspace.com/opensearch/video?
   *  Details:  http://wiki.developer.myspace.com/index.php?title=Open_Search
   *  Description: Get Video Search
   *  @param mixed   $searchTerms   search keywords
   *  @param integer $startIndex    Indicates the index of the first item to retrieve from the query set
   *  @param integer $count			total number of records
   *  @param string  $searchBy      which field the search should go through. Default is all the fields (yomi is only available to ja-jp culture) [ex. searchBy=name or searchBy=displayname or searchBy=email or searchBy=yomi] 
   *  @param string  $culture 		the culture context of the search; for instance japan is ja-jp; default is en-us [ex. culture=en-us] 
   *  @param string  $tag           Determine if this is a tag search [ex. tag=1] 
   *  @param string  $videomode     Determine if this is a tag search [ex. videoMode=1 (music videos) or videoMode=2 (official)] 
   *  @return object of php object representing the JSON in which the list of search
   */
  
  public function searchVideos($searchTerms, $startPage=1, $count=10, $searchBy=NULL, $culture=NULL, $tag=NULL, $videoMode=NULL)
  {

  	$REST = "http://api.myspace.com/opensearch/videos?";
  	$params = array('format' => 'json', 
  					'searchTerms' => $searchTerms,
  					'count' => (empty($count) ? 10 : $count),
  					'startPage' => (empty($startPage) ? 1 : $startPage),
  					'culture' => $culture,
  					'tag' => $tag,
  					'videoMode' => $videoMode);  					
	
  	$responseJSON = $this->context->call($REST, $params, 'GET');
  	//parseJSON is a static method and does not effect the object
  	return MySpaceUtils::parseJSON($responseJSON);

  }
   
}

?>